<template>
	<view class="makeorder" id="makeorder">
		<view class="step">
			<van-steps
			  :steps="steps"
			  :active="active"
			/>
		</view>
		
		<view class="address" @click="choseAddress" >
			<view class="info" v-if="defAddress.id">
				<view class="left-icon">
					<text class="iconfont icon-location"></text>
				</view>
				<view class="info_txt">
					<view class="add_info">
						{{ defAddress.nativenative }} {{ defAddress.address }}
					</view>
					<view class="user_info">
						<view class="name">
							{{ defAddress.name }}
						</view>
						<view class="phone">
							{{ defAddress.phone }}
						</view>
					</view>
				</view>
			</view>
			<view class="tip" v-else  style="text-align: center;">
				<text class="iconfont icon-dingwei"></text>选择地址
			</view>
			<view class="icon" style="margin-top: 5rpx;">
				<van-icon name="arrow" />
			</view>
		</view>
		
		<!-- 商家信息 -->
		<view class="shop_info">
			<view class="shop_left">
				<image :src="shopData.logo" mode=""></image>
			</view>
			<view class="shop_right">
				<view class="shop_name">
					<view class="mark" >
						<van-button type="info" icon="user-o" round size="mini" v-if="shopData.approve == 1">认证</van-button>
						<van-button   round size="mini" v-else>未认证</van-button>
					</view>
					<view class="s_name">
						{{ shopData.companyname }}
					</view>
				</view>
				
				<!-- 评分 -->
				<view class="rate" style="font-size: 26rpx;">
					<view class="star" style="color: orange;">
						<text class="iconfont icon-star" style="line-height: 30rpx;"></text>
						<text style="line-height: 30rpx;">5.0</text>
					</view>  
					<view class="done" style="line-height: 30rpx;margin-left: 50rpx;">
						已完成<text>5</text>次服务
					</view>
					
				</view>
				<!-- <view class="money">
					免定金
				</view> -->
			</view>
		</view>
		<view class="formData">
			<van-field label="服务时间" :value="currentDate" left-icon="clock-o" use-button-slot>
				<van-button slot="button" size="mini" type="primary" @click="choseTime">选择时间</van-button>
			</van-field>
			<van-field label="备注" :value="orderData.remark" :disabled="disabled" clearable @change="beiChange" left-icon="comment-o" use-button-slot placeholder="备注或录音">
				<van-button slot="button" size="mini" type="primary" v-if="!orderData.remark" @click="getAudio">录音</van-button>
				<van-button slot="button" size="mini" icon="play-circle-o"  v-if="audioSrc" type="success" @click="onPlays">播放</van-button>
			</van-field>
		</view>
		
		<!-- 时间选择器 -->
		<view class="time_chose" v-if="timeShow">
			<van-datetime-picker
			  type="datetime"
			  :value="currentDate"
			  :min-date="minDate"
			  @confirm="onConfirm"
			  
			/>
		</view>
		
		<!-- tijiao -->
		<van-goods-action>
		  <van-goods-action-icon
		    icon="chat-o"
		    text="首页"
		    @click="goIndex"
		  />
		  
		  <van-goods-action-button
		    text="个人中心"
		    type="warning"
		    @click="onfavButton"
		  />
		  <van-goods-action-button
		    text="立即下单"
		    @click="onClickButton"
		  />
		</van-goods-action>
		
	</view>
</template>

<script>
	import {getLocaltion, timeFormat} from "@/post.js"
	var audioPlayer = uni.createInnerAudioContext()
	export default {
		data() {
			return {
				steps: [
				      {
				        text: '选择商家',
				        
				      },
				      {
				        text: '下单',
				        
				      },
				      {
				        text: '商家服务',
				      },
				      {
				        text: '订单完成',
				      }
				    ],
				active: "1",
				minDate: new Date().getTime(),
				currentDate:timeFormat(new Date().getTime()),
				orderData: {
					remark: "",
					time: "",
					voice: ""
				},
				timeShow: false,
				itemid: "",
			}
		},
		computed:{
			audioSrc() {
				return this.$store.state.audioSrc
			},
			shopData() {
				return this.$store.state.shopData
			},
			defAddress() {
				return this.$store.state.defaultAddress ? this.$store.state.defaultAddress : ""
			},
		},
		onLoad(e) {
			console.log(e);
			console.log(this.shopData);
			if(e.itemname) {
				this.itemid = e.itemid
				uni.setNavigationBarTitle({
					title: e.itemname
				})
				
			}
		},
		onShow() {
			
		},
		methods: {
			
			// 显示时间picker
			choseTime() {
				this.timeShow = true
			},
			// 确定选择时间
			onConfirm(e) {
				console.log(e);
				let time = timeFormat(e.detail)
				this.timeShow = false
				console.log(time);
				this.currentDate = time
			},
			// beizhu
			beiChange(e) {
				this.orderData.remark = e.detail
			},
			// 去录音界面
			getAudio() {
				
			},
			// 播放mp3
			onPlays() {
				audioPlay.src = this.audioSrc
				audioPlay.play()
			},
			// 选择地址
			choseAddress() {
				uni.navigateTo({
					url:"/pages/addresslist/addresslist"
				})
			},
			// 去首页
			goIndex() {
				uni.switchTab({
					url:"/pages/index/index"
				})
			},
			// 个人中心
			onfavButton() {
				uni.switchTab({
					url:"/pages/my/my"
				})
			},
			// 下单
			onClickButton() {
				let data = {
					token: this.token,
					category,
					acreage: acreage ? acreage : "0",
					servicetime:this.currentDate,
					area,
					remark: remark ? remark : "无备注",
					type: this.type
				}
				if(this.ChoseServer.id) {
					data.category = this.ChoseServer.id
					data.pid = this.ChoseServer.pid
				}
				
				uni.request({
					url: `${self.$Request_Url}/Index/indent`,
					method:"POST",
					data: data,
					success( res ) {
						let code = res.data.code 
						if(code == 202) {
							uni.showToast({
								title:"发布成功",
								icon: "success"
							})
							setTimeout(() => {
								uni.switchTab({
									url:"/pages/index/index"
								})
							}, 2000)
						}
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	#makeorder {
		width: 100%;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		.address {
			// text-align: center;
			width: 100%;
			display: flex;
			align-items: center;
			padding: 20rpx 30rpx;
			box-sizing: border-box;
			border-top: 1px solid #f2f2f2;
			border-bottom: 1px solid #f2f2f2;
			.tip {
				// font-size: 24rpx;
				width: 600rpx;
				line-height: 32rpx;
			}
			.info {
				flex: 1;
				display: flex;
				align-items: center;
				font-size: 26rpx;
				padding-left: 10rpx;
				.info_txt {
					width: 100%;
					padding: 0 20rpx;
				}
				.left_icon {
					color: #007AFF;
					text-align: center;
				}
				.add_info {
					flex: 1;
					
				}
				.user_info {
					width: 100%;
					display: flex;
					align-items: center;
					.phone {
						margin-left: 20rpx;
					}
				}
			}
			.icon {
				width: 50rpx;
				color: #007AFF;
			}
		}
		.shop_info {
			width: 100%;
			display: flex;
			box-sizing: border-box;
			.shop_left {
				width: 150rpx;
				height: 150rpx;
				image {
					width: 150rpx;
					height: 150rpx;
				}
			}
			.shop_right {
				margin-left: 20rpx;
				flex:1;
				.shop_name {
					width: 100%;
					display: flex;
					align-items: center;
					padding: 5rpx 0;
					.mark{
						margin-right: 20rpx;
						width: 100rpx;
						border-radius: 20rpx;
					}
					.s_name {
						flex: 1;
						margin-left: 10rpx;
						font-size: 30rpx;
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
					}
				}
				.rate {
					width: 100%;
					display: flex;
					align-items: center;
					padding: 5rpx 0;
				}
			}
		}
	}
</style>
